@extends('admin.layout.layout')
<style>
    .mobile .content {
        margin: auto 0;
        height: 550px;
        width: 300px;
        background-repeat: no-repeat;
        background-size: 100% 100%;
        background-image: url('{{ asset('static/xadmin/images/WechatIMG42.png') }}')
    }

    .mobile .content .quan-content {
        width: 220px;
        height: 100px;
        position: absolute;
        top: 0;
        left: 0;
        right: -12px;
        bottom: 0;
        margin: auto;
        border: 1px solid rgba(204, 204, 204, 1);
    }

    .quan-content-left {
        height: 100%;
        border-right: 1px dashed rgba(204, 204, 204, 1)
    }

    .quan-content-left-title {
        height: 50%;
        text-align: center;
    }

    .quan-content-left-title-content {
        line-height: 58px;
        font-size: 23px;
    }

    .quan-content-left-title-content p {
        width: 100%;
        height: auto;
        word-wrap: break-word;
        word-break: break-all;
        overflow: hidden;
    }

    .quan-content-right-title-content {
        line-height: 58px;
        font-size: 16px;
    }

    .quan-content-right-title-content_ {
        font-size: 14px;
    }

</style>
@section('content')
    <div class="layui-fluid">
        <div class="layui-fluid layui-card">
            <div class="layui-row ">

                <div class="layui-col-md11">
                    <form class="layui-form" lay-filter="form1">

                        <div class="layui-form-item promotion_mode_child">
                            <div class="layui-inline">
                                <label class="layui-form-label">标题</label>
                                <div class="layui-input-inline" style="width: 500px;">
                                <input name="name"  placeholder="请输入文章标题" class="layui-input" value="{{$info->title??''}}"></input>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item promotion_mode_child">
                            <div class="layui-inline">
                                <label class="layui-form-label">标签</label>
                                <div class="layui-input-inline" style="width: 500px;">
                                    <div id="demo1" class="xm-select-demo"></div>
                                </div>
                            </div>
                            
                        </div>

                        {{-- <div class="layui-form-item promotion_mode_child">
                            <div class="layui-inline">
                                <label class="layui-form-label">是否显示</label>
                                <div class="layui-input-inline" style="width: 500px;padding-top: 8px">
                                    <input type="checkbox" name="is_show" lay-skin="switch" lay-text="是|否" value="1"
                                    @if (isset($info->is_show))
                                        @if ($info->is_show == '是')
                                            checked     
                                        @endif     
                                    @endif
                                    >
                                </div>
                            </div>
                        </div> --}}


                        <input type="hidden" id="id" value="{{$info->id??''}}">
                        <input type="hidden" id="method" 
                        @if (isset($info->id))
                            value = 'put'    
                        @else
                            value = 'post'    
                        @endif
                        >
                        <div class="layui-form-item"></div>
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    <script>
        layui.use(['form', 'layer','laydate','layedit'],
            function () {
                var form = layui.form,
                    laydate = layui.laydate,
                    layedit = layui.layedit;

                var demo1 = xmSelect.render({
                    el: '#demo1',
                    prop: {
                        value: 'id',
                    }, 
                    max: 3,
                    name:'tag_id',
                    pageEmptyShow: false,
                    filterable: true,
                    paging: true,
	                pageRemote: true,
                    remoteMethod: function(val, cb, show, pageIndex){
                        //val: 搜索框的内容, 不开启搜索默认为空, cb: 回调函数, show: 当前下拉框是否展开, pageIndex: 当前第几页
                        
                        //这里的axios类似于ajax
                        axios({
                            method: 'get',
                            url: '{{asset('admin/getTags')}}',
                            params: {
                                name: val,
                                limit:10,
                                page:pageIndex,
                            }
                        }).then(response => {
                            //这里是success的处理
                            console.log(response.data);
                            var res = response.data;
                            //回调需要两个参数, 第一个: 数据数组, 第二个: 总页码
                            cb(res.data.data, Math.ceil(res.data.total/10))
                        }).catch(err => {
                            //这里是error的处理
                            cb([], 0);
                        });
                    }
                })

                form.render();
                form.on('submit(add)',function (data) {
                    let url = '',
                        id = $('#id').val(),
                        method = $('#method').val();
                    if(method == 'post'){
                        url = '{{asset('admin/tags/store')}}'
                    }else{
                        url = '{{asset('admin/tags')}}/' + id
                    }
                    $.ajax({
					  url:url,
					  type:method,
					  data:data.field,
					  dataType:"json",
					  success:function(res){	
                          console.log(res);
                          if (res.status == 'success') {
                            layer.alert(res.msg,{icon:6},function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            })
                        } else {
                            layer.alert(res.msg, {
                                icon: 5
                            });
                        }					 
					  }				  				  
				     }); 				 									  			  
				    return false;
                    });
            });

    </script>
@endsection
